﻿<?xml version="1.0" encoding="utf-8" ?>
<c2eventsheet>
    <!--All the 'name' attributes are ignored by Construct 2 - they are there for readability only.-->
    <name>EventSheet1</name>
    <events>
        <variable comment="To store previous angle of rotation to figure out if we have reached an overlap" constant="0" name="previousLayerAngle" sid="99" static="0" type="number">0</variable>
        <variable comment="Used to identify if a rotation is in progress" constant="0" name="isRotating" sid="44" static="0" type="number">0</variable>
        <variable comment="Angle to rotate to" constant="0" name="targetAngle" sid="46" static="0" type="number">0</variable>
        <variable comment="By default the angle of gravity is 90 deg, pointing to bottom of screen" constant="0" name="currAngleOfGravity" sid="68" static="0" type="number">90</variable>
        <variable constant="0" name="isAntiClockwise" sid="79" static="0" type="number">1</variable>
        <comment>Uncomment for debugging</comment>
        <event-block disabled="1" sid="26">
            <conditions>
                <condition id="-1" name="Every tick" sid="27" type="System" />
            </conditions>
            <actions>
                <action id="0" name="Set text" sid="28" type="txtPlayerAngle">
                    <param id="0" name="Text">&quot;PlayerAngle=&quot; &amp; Player.Angle</param>
                </action>
                <action id="0" name="Set text" sid="38" type="txtPlatformAngleOfGravity">
                    <param id="0" name="Text">&quot;PlatformAngleOfGravity=&quot;  &amp; Player.Platform.MovingAngle</param>
                </action>
                <action id="0" name="Set text" sid="40" type="txtLayoutAngle">
                    <param id="0" name="Text">&quot;TagetAngle=&quot; &amp; targetAngle &amp; &quot;LayerAngle=&quot; &amp; LayerAngle(1)</param>
                </action>
            </actions>
        </event-block>
        <comment>If Left arrow is down, we need to rotate the layer anticlockwise and for Right arrow, it would be clockwise</comment>
        <event-block sid="80">
            <conditions>
                <condition id="2" name="Key is down" sid="82" type="Keyboard">
                    <param id="0" name="Key">37 (Left arrow)</param>
                </condition>
            </conditions>
            <actions>
                <action id="-9" name="Set value" sid="83" type="System">
                    <param id="0" name="Variable">isAntiClockwise</param>
                    <param id="1" name="Value">1</param>
                </action>
            </actions>
        </event-block>
        <event-block sid="84">
            <conditions>
                <condition id="2" name="Key is down" sid="89" type="Keyboard">
                    <param id="0" name="Key">39 (Right arrow)</param>
                </condition>
            </conditions>
            <actions>
                <action id="-9" name="Set value" sid="86" type="System">
                    <param id="0" name="Variable">isAntiClockwise</param>
                    <param id="1" name="Value">0</param>
                </action>
            </actions>
        </event-block>
        <comment>When colliding with the Trigger rectangles, setup the target angle</comment>
        <event-block sid="41">
            <conditions>
                <condition id="0" name="On collision with another object" sid="42" type="Player">
                    <param id="0" name="Object">RotationDetector</param>
                </condition>
                <condition id="-14" name="Compare variable" sid="56" type="System">
                    <param id="0" name="Variable">isRotating</param>
                    <param id="1" name="Comparison">0</param>
                    <param id="2" name="Value">0</param>
                </condition>
            </conditions>
            <actions>
                <action id="11" name="Set collisions enabled" sid="76" type="RotationDetector">
                    <param id="0" name="Collisions">0</param>
                </action>
                <action id="-9" name="Set value" sid="45" type="System">
                    <param id="0" name="Variable">isRotating</param>
                    <param id="1" name="Value">1</param>
                </action>
                <action behavior="Platform" id="11" name="Set enabled" sid="73" type="Player">
                    <param id="0" name="State">0</param>
                </action>
                <action id="-9" name="Set value" sid="100" type="System">
                    <param id="0" name="Variable">previousLayerAngle</param>
                    <param id="1" name="Value">LayerAngle(1)</param>
                </action>
            </actions>
            <sub-events>
                <comment>If rotating anticlockwise, we need to subtract 90 deg. Also make sure to make it a positve angle </comment>
                <event-block sid="90">
                    <conditions>
                        <condition id="-14" name="Compare variable" sid="91" type="System">
                            <param id="0" name="Variable">isAntiClockwise</param>
                            <param id="1" name="Comparison">0</param>
                            <param id="2" name="Value">1</param>
                        </condition>
                    </conditions>
                    <actions>
                        <action id="-9" name="Set value" sid="94" type="System">
                            <param id="0" name="Variable">targetAngle</param>
                            <param id="1" name="Value">(targetAngle-90+360)%360</param>
                        </action>
                    </actions>
                </event-block>
                <comment>If totating clockwise, we can use the angle as it is</comment>
                <event-block sid="92">
                    <conditions>
                        <condition id="-22" name="Else" sid="93" type="System" />
                    </conditions>
                    <actions>
                        <action id="-9" name="Set value" sid="47" type="System">
                            <param id="0" name="Variable">targetAngle</param>
                            <param id="1" name="Value">(targetAngle+90)</param>
                        </action>
                    </actions>
                </event-block>
            </sub-events>
        </event-block>
        <comment>If currently rotating, perform adjusments to angle</comment>
        <event-block sid="48">
            <conditions>
                <condition id="-14" name="Compare variable" sid="49" type="System">
                    <param id="0" name="Variable">isRotating</param>
                    <param id="1" name="Comparison">0</param>
                    <param id="2" name="Value">1</param>
                </condition>
            </conditions>
            <actions />
            <sub-events>
                <event-block sid="95">
                    <conditions>
                        <condition id="-14" name="Compare variable" sid="124" type="System">
                            <param id="0" name="Variable">isAntiClockwise</param>
                            <param id="1" name="Comparison">0</param>
                            <param id="2" name="Value">0</param>
                        </condition>
                    </conditions>
                    <actions>
                        <action id="-23" name="Set layer angle" sid="50" type="System">
                            <param id="0" name="Layer">1</param>
                            <param id="1" name="Angle">LayerAngle(1) + 90*dt </param>
                        </action>
                        <action id="-8" name="Set angle" sid="57" type="Player">
                            <param id="0" name="Angle">Player.Angle + 90*dt</param>
                        </action>
                    </actions>
                    <sub-events>
                        <comment>The or condition is needed when going from say 270 deg to 0 deg</comment>
                        <event-block any="1" sid="97">
                            <conditions>
                                <condition id="-8" name="Compare two values" sid="52" type="System">
                                    <param id="0" name="First value">LayerAngle(1)</param>
                                    <param id="1" name="Comparison">5</param>
                                    <param id="2" name="Second value">targetAngle</param>
                                </condition>
                                <condition id="-8" name="Compare two values" sid="101" type="System">
                                    <param id="0" name="First value">previousLayerAngle</param>
                                    <param id="1" name="Comparison">4</param>
                                    <param id="2" name="Second value">LayerAngle(1)</param>
                                </condition>
                            </conditions>
                            <actions>
                                <action id="-9" name="Set value" sid="114" type="System">
                                    <param id="0" name="Variable">isRotating</param>
                                    <param id="1" name="Value">0</param>
                                </action>
                            </actions>
                        </event-block>
                    </sub-events>
                </event-block>
                <event-block sid="104">
                    <conditions>
                        <condition id="-22" name="Else" sid="105" type="System" />
                    </conditions>
                    <actions>
                        <action id="-23" name="Set layer angle" sid="106" type="System">
                            <param id="0" name="Layer">1</param>
                            <param id="1" name="Angle">LayerAngle(1) - 90*dt </param>
                        </action>
                        <action id="-8" name="Set angle" sid="107" type="Player">
                            <param id="0" name="Angle">Player.Angle - 90*dt</param>
                        </action>
                    </actions>
                    <sub-events>
                        <event-block sid="111">
                            <conditions>
                                <condition id="-8" name="Compare two values" sid="112" type="System">
                                    <param id="0" name="First value">LayerAngle(1)</param>
                                    <param id="1" name="Comparison">3</param>
                                    <param id="2" name="Second value">targetAngle</param>
                                </condition>
                            </conditions>
                            <actions>
                                <action id="-9" name="Set value" sid="55" type="System">
                                    <param id="0" name="Variable">isRotating</param>
                                    <param id="1" name="Value">0</param>
                                </action>
                            </actions>
                        </event-block>
                        <event-block sid="108">
                            <conditions>
                                <condition id="-14" name="Compare variable" sid="109" type="System">
                                    <param id="0" name="Variable">previousLayerAngle</param>
                                    <param id="1" name="Comparison">1</param>
                                    <param id="2" name="Value">0</param>
                                </condition>
                                <condition id="-14" name="Compare variable" sid="110" type="System">
                                    <param id="0" name="Variable">previousLayerAngle</param>
                                    <param id="1" name="Comparison">2</param>
                                    <param id="2" name="Value">LayerAngle(1)&#x0D;&#x0A;</param>
                                </condition>
                            </conditions>
                            <actions>
                                <action id="-9" name="Set value" sid="113" type="System">
                                    <param id="0" name="Variable">isRotating</param>
                                    <param id="1" name="Value">0</param>
                                </action>
                            </actions>
                        </event-block>
                    </sub-events>
                </event-block>
                <comment>If rotation is done, make sure to set the final values and renable behaviors</comment>
                <event-block sid="51">
                    <conditions>
                        <condition id="-14" name="Compare variable" sid="98" type="System">
                            <param id="0" name="Variable">isRotating</param>
                            <param id="1" name="Comparison">0</param>
                            <param id="2" name="Value">0</param>
                        </condition>
                    </conditions>
                    <actions>
                        <action id="-23" name="Set layer angle" sid="54" type="System">
                            <param id="0" name="Layer">1</param>
                            <param id="1" name="Angle">targetAngle</param>
                        </action>
                        <action id="-8" name="Set angle" sid="72" type="Player">
                            <param id="0" name="Angle">targetAngle</param>
                        </action>
                    </actions>
                    <sub-events>
                        <event-block sid="115">
                            <conditions>
                                <condition id="-14" name="Compare variable" sid="96" type="System">
                                    <param id="0" name="Variable">isAntiClockwise</param>
                                    <param id="1" name="Comparison">0</param>
                                    <param id="2" name="Value">0</param>
                                </condition>
                            </conditions>
                            <actions>
                                <action id="-9" name="Set value" sid="69" type="System">
                                    <param id="0" name="Variable">currAngleOfGravity</param>
                                    <param id="1" name="Value">(currAngleOfGravity+90)%360</param>
                                </action>
                            </actions>
                        </event-block>
                        <event-block sid="119">
                            <conditions>
                                <condition id="-22" name="Else" sid="120" type="System" />
                            </conditions>
                            <actions>
                                <action id="-11" name="Subtract from" sid="118" type="System">
                                    <param id="0" name="Variable">currAngleOfGravity</param>
                                    <param id="1" name="Value">90</param>
                                </action>
                            </actions>
                        </event-block>
                        <event-block sid="121">
                            <conditions />
                            <actions>
                                <action id="-9" name="Set value" sid="125" type="System">
                                    <param id="0" name="Variable">targetAngle</param>
                                    <param id="1" name="Value">targetAngle %360</param>
                                </action>
                                <action behavior="Platform" id="10" name="Set angle of gravity" sid="66" type="Player">
                                    <param id="0" name="Angle">currAngleOfGravity</param>
                                </action>
                                <action behavior="Platform" id="11" name="Set enabled" sid="74" type="Player">
                                    <param id="0" name="State">1</param>
                                </action>
                                <action id="-16" name="Wait" sid="122" type="System">
                                    <param id="0" name="Seconds">2</param>
                                </action>
                                <action id="11" name="Set collisions enabled" sid="123" type="RotationDetector">
                                    <param id="0" name="Collisions">1</param>
                                </action>
                            </actions>
                        </event-block>
                    </sub-events>
                </event-block>
                <event-block sid="102">
                    <conditions />
                    <actions>
                        <action id="-9" name="Set value" sid="103" type="System">
                            <param id="0" name="Variable">previousLayerAngle</param>
                            <param id="1" name="Value">LayerAngle(1)</param>
                        </action>
                    </actions>
                </event-block>
            </sub-events>
        </event-block>
        <comment>Level complete!</comment>
        <event-block sid="131">
            <conditions>
                <condition id="0" name="On collision with another object" sid="132" type="Player">
                    <param id="0" name="Object">Target</param>
                </condition>
            </conditions>
            <actions />
        </event-block>
    </events>
</c2eventsheet>
